package skeleton.android;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class CPU extends Activity 
{
	//TextView MessageText;
	TableLayout myTable;
	
	@Override
	public void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
	    super.setTitle("CPU info");	 
	    this.setContentView(R.layout.cpu);
	    
	    myTable = (TableLayout) findViewById(R.id.tableLayout1);
	    
	    /* reading proc fs */
		BufferedReader reader = null;
		String load = "";
			
		try 
		{
			//CPU-INFO
			reader = new BufferedReader( new InputStreamReader( new FileInputStream( "/proc/cpuinfo" ) ), 1000 );
			
			load = reader.readLine();
			
			reader.close();
			
			String[] toks = load.split(" ");
			
			for(int i=0; i < toks.length; i++)
			{
				TableRow tr = new TableRow(this);
				
				TextView processID = new TextView(this);
				processID.setText(toks[i].toString());
				
				tr.addView(processID);
				
				myTable.addView(tr, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
			}
			
			//PID - STATM
			/*
			reader = new BufferedReader( new InputStreamReader( new FileInputStream( "/proc/1549/statm" ) ), 1000 );
			
			load = reader.readLine();
			
			reader.close();
			
			toks = load.split(" ");
			
			for(int i=0; i < toks.length; i++)
			{
				TableRow tr = new TableRow(this);
				
				TextView processID = new TextView(this);
				processID.setText(">"+toks[i].toString());
				
				tr.addView(processID);
				
				myTable.addView(tr, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
			} */
			
			
			//CPU-INFO
			/*
			reader = new BufferedReader( new InputStreamReader( new FileInputStream( "/proc/meminfo" ) ), 1000 );
			
			load = reader.readLine();
			
			reader.close();
			
			toks = load.split(" ");
			
			for(int i=0; i < toks.length; i++)
			{
				TableRow tr = new TableRow(this);
				
				TextView processID = new TextView(this);
				processID.setText(">>"+toks[i].toString());
				
				tr.addView(processID);
				
				myTable.addView(tr, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
			}
			*/	
		} 
        catch (IOException e) { e.printStackTrace(); }
			
	}

}
